package com.kly.manager.websocket.model;

import lombok.Getter;

import java.util.Objects;

/**
 * 消息接收者类型枚举
 */
@Getter
public enum ReceiverType {
    /**
     * 用户
     */
    USER(1, "用户"),
    /**
     * 群组
     */
    GROUP(0, "群组");

    private final Integer value;
    private final String description;

    ReceiverType(Integer value, String description) {
        this.value = value;
        this.description = description;
    }

    /**
     * 根据字符串值查找对应的枚举
     *
     * @param value 枚举值（如 "USER" 或 "GROUP"）
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果值无效
     */
    public static ReceiverType fromString(Integer value) {
        for (ReceiverType type : values()) {
            if (Objects.equals(type.getValue(), value)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Invalid receiver type: " + value);
    }
}